package org.fly.controller.wap.customer;

import org.fly.bean.Customer;
import org.fly.bean.Page;
import org.fly.bean.Product;
import org.fly.bean.Supplier;
import org.fly.bean.query.ProductQuery;
import org.fly.bean.warpper.ProductPriceWarpper;
import org.fly.bean.warpper.ProductWarpper;
import org.fly.controller.AbstractController;
import org.fly.enums.Relation;
import org.fly.service.ProductService;
import org.fly.utils.JsonUtils;
import org.fly.utils.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by rongzhao.zhu on 2018/3/31.
 */
@Controller
@RequestMapping("/wap/customer/product/")
public class WapCProductController extends AbstractController {
    @Autowired
    ProductService productService;

    @RequestMapping(value = "queryPage", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryPage(ProductQuery query){
        List<ProductWarpper> list = productService.listWarpper(query );
        long count = this.productService.count(query);
        Page page = new Page(query.getPage(),query.getSize());
        page.setData(list);
        page.setTotal(count);
        return JsonUtils.encode(createDataTip(page));
    }

    @RequestMapping(value = "find",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String find(String id){
        Customer customer = (Customer) UserContext.getUser();
        String customerId = customer.getId();
        ProductPriceWarpper  productPriceWarpper = productService.find(id,customerId);
        return toJSONString(createDataTip(productPriceWarpper));
    }
}
